﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace oneNet
{
    public partial class Form2 : Form
    {
        public string url;
        public string api_key;
        public int time;
        public HashSet<string> uniqueNames = new HashSet<string>();

        public Form2()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!textBox1.Text.Equals("")&& !textBox2.Text.Equals("")) {
                url = textBox1.Text; 
               
                api_key = textBox2.Text;
               
            }
            if (numericUpDown1.Value == 0)
            {
                time = 10;
            }
            else {
                time = (int)numericUpDown1.Value;
            }
            Console.WriteLine( " " + url + " "+ api_key + " " + time);
            
            ListBox.ObjectCollection items = listBox1.Items;

            // 遍历 Items 集合
            foreach (object item in items)
            {
                uniqueNames.Add(item.ToString());
            }
            // 使用 foreach 循环遍历 List
            foreach (string name in uniqueNames)
            {
                // 打印 List 中的每个元素
                Console.WriteLine(name);
            }
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        int selectedIndex = -1;
        int old_selectedIndex = -1;
        private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            selectedIndex = listBox1.SelectedIndex;
            if (selectedIndex != old_selectedIndex)
            {
                old_selectedIndex = selectedIndex;
                return;
            }
            selectedIndex = old_selectedIndex = -1;

            DialogResult dr = MessageBox.Show("是否删除", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            if (dr == DialogResult.OK)
            {
                Console.WriteLine("1");
                listBox1.Items.Remove(listBox1.SelectedItem);
                
            }
            else
            {
                Console.WriteLine("2");
            }
        }
        private void add_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(textBox1.Text);
            //list.Add(textBox1.Text);
            // 获取 ListBox 的 Items 属性
        }
    }
}
